﻿<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/5/12
 * Time: 12:06
 */
include "MySqlConnect.php";
$mysqlconnect = new MySqlConnect();
$jieshou = $_REQUEST["jieshou"];
//$openid = $_REQUEST["openid"];


if($jieshou=="yemian")
{
	date_default_timezone_set('PRC');
	$yemian = $_REQUEST["yemian"];$type = $_REQUEST["type"];$nowtime = date('Y-m-d H:i:s');
	$jieguo = $mysqlconnect->ExecuteData("insert into yemian values(null,'$openid','$yemian','$type','$nowtime')");
	echo $jieguo;
}
if($jieshou=="checkopenid"){
	date_default_timezone_set('PRC');
	$openid = $_REQUEST["openid"];
	$nowtime = date('Y-m-d H:i:s');
	$mysqlconnect = new MySqlConnect();
	$querystr = "select * from user where openid='$openid'";
	$info =json_decode($mysqlconnect->GetDataSetJsonPHP($querystr)) ;
	$count = count($info);
//	echo  $count;
	if($count=="0")
	{
		echo $count;
//		try
//		{
//			$jieguo = $mysqlconnect->ExecuteData("insert into user values(null,'$openid','','','0','0','0','','','','','','')");
//			echo $jieguo;
//		}
//		catch(Exception $err){
////			echo $err;
//		}

//		echo "qin".$jieguo;
	}
	else
	{
		echo $mysqlconnect->GetDataSetJsonPHP($querystr);
	}
	
	
}
if($jieshou=="AddUser"){
	date_default_timezone_set('PRC');
	$openid = $_REQUEST["openid"];
//	$headimg = $_REQUEST["headimg"];
//	$sex = $_REQUEST["sex"];
//	$city = $_REQUEST["city"];
	$nowtime = date('Y-m-d H:i:s');
	$mysqlconnect = new MySqlConnect();
	$querystr = "select * from user where openid='$openid'";
	$info =json_decode($mysqlconnect->GetDataSetJsonPHP($querystr)) ;
	$count = count($info);
	if($count=="0")
	{
		echo $count;
	}
	else
	{
		echo $mysqlconnect->GetDataSetJsonPHP($querystr);
	}
	
	
}
if($jieshou=="choujiang"){
	date_default_timezone_set('PRC');
//	$openid = $_REQUEST["openid"];
	$nowtime = date('Y-m-d H:i:s');
	$xiaoshi = date("H");
	$mysqlconnect = new MySqlConnect();
	$querystr = "select * from yemian where remark='baoming'";
	$info =json_decode($mysqlconnect->GetDataSetJsonPHP($querystr));
	$count = count($info);
	$choujiang = 0;
	if($count<1)
	{
		if($xiaoshi!="17" && $xiaoshi!="18" && $xiaoshi!="19")
		{
			$gailv = mt_rand(0, 100);
			if($gailv>888)
			{
				$choujiang=0;
			}
			
		}
	}
	
	echo $choujiang;
}
if($jieshou=="tijiao"){
	date_default_timezone_set('PRC');
	$xingming = $_REQUEST["xingming"];
	$shoujihao = $_REQUEST["shoujihao"];
	$openid = $_REQUEST["openid"];
	$nowtime = date('Y-m-d H:i:s');
	$mysqlconnect = new MySqlConnect();
	
//	try{
//		$jieguo1 = $mysqlconnect->ExecuteData("update user set xingming='$xingming',shoujihao='$shoujihao',tjtime='$nowtime' where openid='$openid'");
//	}
//	catch(exception exx){
//		
//	}
	
	$jieguo = $mysqlconnect->ExecuteData("insert into yemian values(null,'$openid','$xingming','$shoujihao','$nowtime','baoming')");
	echo $jieguo;
//	echo $mysqlconnect->GetDataSetJsonPHP($querystr);
}
if($jieshou=="tijiaotupian"){
	date_default_timezone_set('PRC');
	$pic = $_REQUEST["pic"];
	$openid = $_REQUEST["openid"];
	$xuhao = $_REQUEST["xuhao"];
	$nowtime = date('YmdHis');
	$picName ='shangchuan/'.$nowtime.'.png';
//  $picBin = str_replace(' ', '+', $picBin);
//  $picBin = preg_replace('/^data:image\/(png|jpeg|jpg);base64,/', '', $picBin);
    $data= base64_decode($pic);
    $result = file_put_contents($picName,$data);  //将流图片转换成图片存在文件夹
//  $jieguo = $mysqlconnect->ExecuteData("update user set tupian='$picName',xuhao='$xuhao' where openid='$openid'");
    $jieguo1 = $mysqlconnect->ExecuteData("insert into yemian values(null,'$openid','$picName','$xuhao','$nowtime','shangchuan')");
    
    echo $picName;
//  echo $jieguo1;
}
if($jieshou=="getlist")
{
	echo $mysqlconnect->GetDataSetJson("select * from yemian where remark='shangchuan	' order by id desc");
	
}
if($jieshou=="getshuju")
{
	$yeshu = $_REQUEST["yeshu"];
//	echo $mysqlconnect->GetDataSetJson("select * from yemian where remark='shangchuan' ORDER BY id desc  limit $yeshu,100");
	echo $mysqlconnect->GetDataSetJson("select * from yemian where remark='shangchuan' ORDER BY id desc");
	
}



?>
